﻿using System;
using System.IO;
using msilgc.runtime;

namespace msilgc.aot {
    class Program {
        static void Main(string[] args) {
            if (args.Length != 2 || !File.Exists(args[0]) || !Directory.Exists(args[1])) {
                WriteUsage();
            } else {
                RunCompiler(new FileInfo(args[0]), new DirectoryInfo(args[1]));
            }
        }

        private static void RunCompiler(FileInfo assemblyFile, DirectoryInfo outputFolder) {
            try {
                new Builder().CompileAssemblyAot(assemblyFile, outputFolder);
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                Environment.ExitCode = 2;
            }
        }

        private static void WriteUsage() {
            Console.WriteLine("Usage: ");
            Console.WriteLine("msilgc.aot [assembly.dll] [output folder]");
            Environment.ExitCode = 1;
        }
    }
}
